package com.company;

import com.company.flyweight.WebSite;
import com.company.flyweight.Company;
import com.company.flyweight.WebSiteFactory;

/**
 * 享元模式测试代码
 */
public class TestForFlyweight {

    public static void main(String[] args) {
        WebSiteFactory factory = new WebSiteFactory();

        //Company是外部状态，作为参数传进去
        //公司1网站使用了模板A
        WebSite companySite1 =  factory.getWebSiteByTemplate("模板A");
        companySite1.use(new Company("公司1"));

        System.out.println("====================================");

        //公司2网站使用了模板B
        WebSite companySite2 =  factory.getWebSiteByTemplate("模板B");
        companySite2.use(new Company("公司2"));

        System.out.println("====================================");

        //公司3网站使用了模板A
        WebSite companySite3 =  factory.getWebSiteByTemplate("模板A");
        companySite3.use(new Company("公司3"));

        System.out.println("====================================");

        System.out.println("网站模板总数:" +factory.getWebsiteTemplateSize());
    }
}
